﻿@model TianYu.CMS.Domain.DomainModel.Article
@{
    ViewBag.Title = "新增/编辑";
    Layout = "~/Areas/Admin/Views/Shared/_Layout_Edit.cshtml";
}
<form class="layui-form" method="post" action="/admin/article/save" id="myForm" autocomplete="off">
    <input type="hidden" value="@Model.Guid" name="Guid" />
    <input type="hidden" value="@Model.PulishStatus" name="PulishStatus" />
    <input type="hidden" value="@Model.IsRecommend.ToString()" name="IsRecommend" />
    <input type="hidden" value="@Model.IsTop.ToString()" name="IsTop" />
    <input type="hidden" value="@Model.IsOriginal.ToString()" name="IsOriginal" />
    <input type="hidden" value="@Model.TitleImg" name="TitleImg" />
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this">基础信息</li>
            <li>详情内容</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-row">
                    <div class="layui-col-xs6">
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:red;">*</span>文章标题</label>
                            <div class="layui-input-block">
                                <input type="text" name="ArticleTitle" required lay-verify="required" autocomplete="off" class="layui-input" maxlength="128" value="@Model.ArticleTitle">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:red;">*</span>所属分类</label>
                            <div class="layui-input-block">
                                <select name="CategoryId" layui-type="search">
                                    @Html.Raw(ViewBag.CategoryList)
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs6">
                        <div class="layui-form-item layui-form-text">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" id="btnUpload1">
                                    <i class="layui-icon">&#xe67c;</i>上传图片
                                </button>
                                <img id="TitleImg" src="@Model.TitleImg" style="width:80px;height:60px;margin-left:10px;@(Model.TitleImg + "" != "" ? "" : "display:none")" />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">副标题</label>
                    <div class="layui-input-block">
                        <textarea name="SubTitle" autocomplete="off" class="layui-textarea" maxlength="200">@Model.SubTitle</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">Keywords</label>
                    <div class="layui-input-block">
                        <input type="text" name="Keywords" autocomplete="off" class="layui-input" maxlength="128" value="@Model.Keywords">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">Description</label>
                    <div class="layui-input-block">
                        <input type="text" name="Description" autocomplete="off" class="layui-input" maxlength="128" value="@Model.Description">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">发布状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" lay-filter="PulishStatus" value="@Model.PulishStatus" lay-skin="switch" lay-text="已发布|未发布" @(Model.PulishStatus == 1 ? "checked" : "")>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs4">
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否原创</label>
                            <div class="layui-input-block">
                                <input type="checkbox" lay-filter="IsOriginal" value="@Model.IsOriginal" lay-skin="switch" lay-text="原创|转载" @(Model.IsOriginal ? "checked" : "")>
                            </div>
                        </div>
                    </div> 
                    <div class="layui-col-xs4">
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否推荐</label>
                            <div class="layui-input-block">
                                <input type="checkbox" lay-filter="IsRecommend" value="@Model.IsRecommend" lay-skin="switch" lay-text="是|否" @(Model.IsRecommend ? "checked" : "")>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs4">
                        <div class="layui-form-item">
                            <label class="layui-form-label">是否置顶</label>
                            <div class="layui-input-block">
                                <input type="checkbox" lay-filter="IsTop" value="@Model.IsTop" lay-skin="switch" lay-text="是|否" @(Model.IsTop ? "checked" : "")>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <textarea name="Content" id="Content">@Model.Content</textarea>
            </div>
        </div>
    </div>
    <div class="layui-footer">
        <button type="button" class="layui-btn layui-btn-primary" onclick="win.close()">关闭</button>
        <button type="button" class="layui-btn" lay-submit lay-filter="formSubmit">保存</button>
    </div>
</form>
@section Scripts{
    <script type="text/javascript">
        $(function () {
            var edtor = initUEditor('Content', "100%", "350");

            layui.use('element', function () {
                var $ = layui.jquery, element = layui.element;
            });
            layui.use('form', function () {
                var form = layui.form;
                form.verify($.verify);
                //监听提交
                form.on('submit(formSubmit)', function (data) {
                    win.showLoading("正在保存...");

                    var roleList = [];
                    roleList.push(parseInt($('#RoleId').val()));
                    $('input[name=UserRoleList]').val(JSON.stringify(roleList));

                    $("#myForm").ajaxSubmit(function (res) {
                        win.hideLoading();
                        if (res.code == 0) {
                            parent.getList();
                            parent.win.success("保存成功");
                            win.close();
                        } else {
                            win.alert(res.message);
                        }
                    });
                    return false;
                });
                form.on('switch(PulishStatus)', function (data) {
                    $('input[name=PulishStatus]').val(data.elem.checked ? 1 : 0);
                });
                form.on('switch(IsOriginal)', function (data) {
                    $('input[name=IsOriginal]').val(data.elem.checked);
                });
                form.on('switch(IsRecommend)', function (data) {
                    $('input[name=IsRecommend]').val(data.elem.checked);
                });
                form.on('switch(IsTop)', function (data) {
                    $('input[name=IsTop]').val(data.elem.checked);
                });
            });

            layui.use('upload', function () {
                var upload = layui.upload;
                var uploadInst1 = upload.render({
                    elem: '#btnUpload1'
                    , url: '/admin/upload/upload'
                    , before: function (res) {
                        win.showLoading("正在上传...");
                    }
                    , done: function (res) {
                        if (res.code == 0) {
                            $("#TitleImg").show().attr("src", res.data[0].saveFilePath);
                            $("input[name='TitleImg']").val(res.data[0].saveFilePath);
                        } else {
                            win.alert("出错了");
                        }

                        win.hideLoading();
                    }
                    , error: function () {
                        win.hideLoading();
                        win.alert("出错了");
                    }
                });
            });
        });
    </script>
}